package co.edu.usbcali.raju.games.chess.client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.util.Scanner;

import jpl.Query;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import co.edu.usbcali.raju.games.chess.controller.ChessController;
import co.edu.usbcali.raju.games.chess.model.AlphaBetaSearch;
import co.edu.usbcali.raju.games.chess.model.EvaluateForce;
import co.edu.usbcali.raju.games.chess.model.EvaluateThreat;
import co.edu.usbcali.raju.games.chess.server.XBoardAdapter;
import co.edu.usbcali.raju.games.chess.server.IXBoardAdapterR;
import co.edu.usbcali.raju.model.ComplexEvaluator;

public class InputXBoardAdapter extends Thread {
	
	static Logger logger;
	private IXBoardAdapterR engine;
	
	public InputXBoardAdapter(IXBoardAdapterR engine) {
		super();
		this.engine = engine;
	}

	@Override
	public void run(){
		BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
//		Scanner scanner=new Scanner(System.in);
		try {
			while(engine.isRunning()){
				String command = br.readLine();
//				String command=scanner.nextLine();
				engine.processComand(command);
			}
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public IXBoardAdapterR getEngine() {
		return engine;
	}

	public void setEngine(XBoardAdapter engine) {
		this.engine = engine;
	}
	

	public static void initProlog(){
		String t3 = "consult('chessEval3.pl')";
		Query q3 = new Query(t3);
		q3.hasSolution();
	//	System.out.println( t3 + " " + (q3.hasSolution() ? "succeeded" : "failed") );
	}
	

}
